package com.example.keli.ui.worldwall;

import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.LinearLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.example.keli.R;
import com.example.keli.api.RetrofitManager;
import com.example.keli.api.http.api.BaseResponse;
import com.example.keli.api.http.api.subscriber.SubscriberListener;
import com.example.keli.base.BaseFragment;
import com.example.keli.base.app.C;
import com.example.keli.ui.center.ActiveAdapter;
import com.example.keli.ui.center.ActiveDetailsActivity;
import com.example.keli.ui.center.ActivieList;
import com.example.keli.ui.userinfo.person.UserInfoActivity;
import com.kennyc.view.MultiStateView;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;

/**
 * description $desc$
 * created by jerry on 2019/3/18.
 */
public class CircleFragment extends BaseFragment {

    private static final String TAG = "ActiveFragment";
    @BindView(R.id.recycler_active)
    RecyclerView recyclerView;
    @BindView(R.id.refreshlayout)
    SwipeRefreshLayout mRefreshlayout;
    View mHeaderView;
    private CircleAdapter circleAdapter;
    private List<CircleBean> mDatas;
    private int mType = 0;//0全部   1我的关注
    private int page = 1;

    public static CircleFragment newInstance(int type) {
        CircleFragment aboutFragment = new CircleFragment();
        Bundle bundle = new Bundle();
        bundle.putInt("type", type);
        aboutFragment.setArguments(bundle);
        return aboutFragment;
    }

    @Override
    protected int layoutId() {
        return R.layout.fragment_circle;
    }

    @Override
    protected void bindData() {
        Bundle bundle = getArguments();
        if (bundle != null){
            mType = bundle.getInt("type");
        }
        initRecycleView();
        loadDatas();
        toActivity(UserInfoActivity.class);
    }

    private void initRecycleView() {
        mDatas = new ArrayList<>();
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(linearLayoutManager);
        circleAdapter = new CircleAdapter(mDatas, getContext(), mType);
        recyclerView.setAdapter(circleAdapter);
        mHeaderView = inflate(R.layout.header_comment_tip);
    }

    @Override
    protected void bindListener() {
        mRefreshlayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                page = 1;
                mDatas.clear();
                loadDatas();
                mRefreshlayout.setRefreshing(false);
                circleAdapter.addHeaderView(mHeaderView);
            }
        });
        circleAdapter.setOnLoadMoreListener(new BaseQuickAdapter.RequestLoadMoreListener() {
            @Override
            public void onLoadMoreRequested() {
                page++;
                loadDatas();
            }
        }, recyclerView);

        mHeaderView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                toActivity(CommentListActivity.class);
            }
        });
    }

    private void loadDatas() {
        for (int i = 0; i < 20; i++) {
            ArrayList<String> photos = new ArrayList<>();
            photos.add("https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1559720563&di=a4bdcbaf7c45f162d2cb3ee0fa4a57f6&src=http://img3.duitang.com/uploads/item/201502/20/20150220235727_MLT5j.jpeg");
            photos.add("https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1559720563&di=a4bdcbaf7c45f162d2cb3ee0fa4a57f6&src=http://img3.duitang.com/uploads/item/201502/20/20150220235727_MLT5j.jpeg");
//            photos.add("https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1559720563&di=a4bdcbaf7c45f162d2cb3ee0fa4a57f6&src=http://img3.duitang.com/uploads/item/201502/20/20150220235727_MLT5j.jpeg");
//            photos.add("https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1559720563&di=a4bdcbaf7c45f162d2cb3ee0fa4a57f6&src=http://img3.duitang.com/uploads/item/201502/20/20150220235727_MLT5j.jpeg");
//            photos.add("https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1559720563&di=a4bdcbaf7c45f162d2cb3ee0fa4a57f6&src=http://img3.duitang.com/uploads/item/201502/20/20150220235727_MLT5j.jpeg");

            CircleBean circleBean = new CircleBean("https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1559720563&di=a4bdcbaf7c45f162d2cb3ee0fa4a57f6&src=http://img3.duitang.com/uploads/item/201502/20/20150220235727_MLT5j.jpeg",
                    "Jam"+i, false, "放假啊苏菲玛索干嘛啦法拉盛",photos,"北京市", "04-21 22:34", "23", "45");
            mDatas.add(circleBean);
            circleAdapter.notifyDataSetChanged();
        }

    }

}
